package com.shiqu.web.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shiqu.core.util.StringUtils;
import com.shiqu.web.bo.FacadeResult;
import com.shiqu.web.bo.Page;
import com.shiqu.web.bo.ReturnServiceCode;
import com.shiqu.web.po.SysUser;
import com.shiqu.web.service.SysService;
@Controller
@RequestMapping("/test")
public class TestController extends BaseController{

	@Autowired
	private SysService sysService;
	
	/**
	 * 根据用户编码查询用户信息
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getUserByUserCode")
	@RequiresPermissions("item:update")
	public @ResponseBody FacadeResult getUserByUserCode(HttpServletRequest request,HttpServletResponse response) throws Exception{
		//1、获取参数
		String userCode = request.getParameter("userCode");
		//2、检查参数
		if(StringUtils.isNull(userCode)){
			//返回异常信息
			return generateException(ReturnServiceCode.CHECK_PARAM_ERROR);
		}
		//3、获取返回数据
		SysUser sysUser  = sysService.getSysUserByUserCode(userCode);
		//4、正常返回数据
		return generateData(sysUser);
	}
	
	/**
	 * 根据用户编码查询用户信息
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getUserByPage")
	public @ResponseBody FacadeResult getUserByPage(HttpServletRequest request,HttpServletResponse response) throws Exception{
		//1、获取参数
		Map<String,Object> paramMap = StringUtils.getParameterMap(request);
		//2、检查参数
		if(StringUtils.isNull(paramMap.get("pageSize"))||StringUtils.isNull(paramMap.get("pageNum"))){
			//返回异常信息
			return generateException(ReturnServiceCode.CHECK_PARAM_ERROR);
		}
		//3、获取返回数据
		Page page  = sysService.getUserByPage(paramMap);
		
		//4、正常返回数据
		return generateData(page.getResult(),page.getTotal());
	}
	
	
	
}
